home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
334_02
/
setshow.c
< prev
next >
Wrap
Text File
|
1991-02-04
|
47KB
|
1,867 lines
/* GNUPLOT - setshow.c */
/*
* Copyright (C) 1986, 1987, 1990 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the modified code. Modifications are to be distributed
* as patches to released version.
*
* This software is provided "as is" without express or implied warranty.
*
*
* AUTHORS
*
* Original Software:
* Thomas Williams, Colin Kelley.
*
* Gnuplot 2.0 additions:
* Russell Lang, Dave Kotz, John Campbell.
*
* send your comments or suggestions to (pixar!info-gnuplot@sun.com).
*
*/
#include <stdio.h>
#include <math.h>
#include "plot.h"
#include "setshow.h"
#define DEF_FORMAT "%g" /* default format for tic mark labels */
#define SIGNIF (0.01) /* less than one hundredth of a tic mark */
/*
* global variables to hold status of 'set' options
*
*/
BOOLEAN autoscale_t = TRUE;
BOOLEAN autoscale_x = TRUE;
BOOLEAN autoscale_y = TRUE;
BOOLEAN autoscale_lt = TRUE;
BOOLEAN autoscale_lx = TRUE;
BOOLEAN autoscale_ly = TRUE;
BOOLEAN clip_points = FALSE;
BOOLEAN clip_lines1 = TRUE;
BOOLEAN clip_lines2 = FALSE;
char dummy_var[MAX_ID_LEN+1] = "x";
char xformat[MAX_ID_LEN+1] = DEF_FORMAT;
char yformat[MAX_ID_LEN+1] = DEF_FORMAT;
enum PLOT_STYLE data_style = POINTS,
func_style = LINES;
BOOLEAN grid = FALSE;
int key = -1; /* default position */
double key_x, key_y; /* user specified position for key */
BOOLEAN log_x = FALSE,
log_y = FALSE;
FILE* outfile;
char outstr[MAX_ID_LEN+1] = "STDOUT";
BOOLEAN polar = FALSE;
BOOLEAN parametric = FALSE;
int samples = SAMPLES;
float xsize = 1.0; /* scale factor for size */
float ysize = 1.0; /* scale factor for size */
int term = 0; /* unknown term is 0 */
char title[MAX_LINE_LEN+1] = "";
char xlabel[MAX_LINE_LEN+1] = "";
char ylabel[MAX_LINE_LEN+1] = "";
double tmin = -5.0,
tmax = 5.0,
xmin = -10.0,
xmax = 10.0,
ymin = -10.0,
ymax = 10.0;
double loff = 0.0,
roff = 0.0,
toff = 0.0,
boff = 0.0;
double zero = ZERO; /* zero threshold, not 0! */
BOOLEAN xzeroaxis = TRUE;
BOOLEAN yzeroaxis = TRUE;
BOOLEAN xtics = TRUE;
BOOLEAN ytics = TRUE;
struct ticdef xticdef = {TIC_COMPUTED};
struct ticdef yticdef = {TIC_COMPUTED};
BOOLEAN tic_in = TRUE;
struct text_label *first_label = NULL;
struct arrow_def *first_arrow = NULL;
/*** other things we need *****/
extern char *strcpy(),*strcat();
extern int strlen();
extern FILE *popen();
/* input data, parsing variables */
extern struct lexical_unit token[];
extern char input_line[];
extern int num_tokens, c_token;
extern char replot_line[];
extern struct udvt_entry *first_udv;
extern double magnitude(),real();
extern struct value *const_express();
/******** Local functions ********/
static void set_label();
static void set_nolabel();
static void set_arrow();
static void set_noarrow();
static void load_tics();
static void load_tic_user();
static void free_marklist();
static void load_tic_series();
static void load_offsets();
static void show_style(), show_range(), show_zero();
static void show_offsets(), show_output(), show_samples(), show_size();
static void show_title(), show_xlabel(), show_ylabel();
static void show_xzeroaxis(), show_yzeroaxis();
static void show_label(), show_arrow(), show_grid(), show_key();
static void show_polar(), show_parametric(), show_tics(), show_ticdef();
static void show_term(), show_plot(), show_autoscale(), show_clip();
static void show_format(), show_logscale(), show_variables();
static void delete_label();
static int assign_label_tag();
static void delete_arrow();
static int assign_arrow_tag();
/******** The 'set' command ********/
void
set_command()
{
static char testfile[MAX_LINE_LEN+1];
#ifdef unix
static BOOLEAN pipe_open = FALSE;
#endif
c_token++;
if (almost_equals(c_token,"ar$row")) {
c_token++;
set_arrow();
}
else if (almost_equals(c_token,"noar$row")) {
c_token++;
set_noarrow();
}
else if (almost_equals(c_token,"au$toscale")) {
c_token++;
if (END_OF_COMMAND) {
autoscale_t = autoscale_x = autoscale_y = TRUE;
} else if (equals(c_token, "xy") || equals(c_token, "yx")) {
autoscale_x = autoscale_y = TRUE;
c_token++;
} else if (equals(c_token, "t")) {
autoscale_t = TRUE;
c_token++;
} else if (equals(c_token, "x")) {
autoscale_x = TRUE;
c_token++;
} else if (equals(c_token, "y")) {
autoscale_y = TRUE;
c_token++;
}
}
else if (almost_equals(c_token,"noau$toscale")) {
c_token++;
if (END_OF_COMMAND) {
autoscale_t = autoscale_x = autoscale_y = FALSE;
} else if (equals(c_token, "xy") || equals(c_token, "tyx")) {
autoscale_x = autoscale_y = FALSE;
c_token++;
} else if (equals(c_token, "t")) {
autoscale_t = FALSE;
c_token++;
} else if (equals(c_token, "x")) {
autoscale_x = FALSE;
c_token++;
} else if (equals(c_token, "y")) {
autoscale_y = FALSE;
c_token++;
}
}
else if (almost_equals(c_token,"c$lip")) {
c_token++;
if (END_OF_COMMAND)
/* assuming same as points */
clip_points = TRUE;
else if (almost_equals(c_token, "p$oints"))
clip_points = TRUE;
else if (almost_equals(c_token, "o$ne"))
clip_lines1 = TRUE;
else if (almost_equals(c_token, "t$wo"))
clip_lines2 = TRUE;
else
int_error("expecting 'points', 'one', or 'two'", c_token);
c_token++;
}
else if (almost_equals(c_token,"noc$lip")) {
c_token++;
if (END_OF_COMMAND) {
/* same as all three */
clip_points = FALSE;
clip_lines1 = FALSE;
clip_lines2 = FALSE;
} else if (almost_equals(c_token, "p$oints"))
clip_points = FALSE;
else if (almost_equals(c_token, "o$ne"))
clip_lines1 = FALSE;
else if (almost_equals(c_token, "t$wo"))
clip_lines2 = FALSE;
else
int_error("expecting 'points', 'one', or 'two'", c_token);
c_token++;
}
else if (almost_equals(c_token,"d$ata")) {
c_token++;
if (!almost_equals(c_token,"s$tyle"))
int_error("expecting keyword 'style'",c_token);
data_style = get_style();
}
else if (almost_equals(c_token,"d$ummy")) {
c_token++;
if (END_OF_COMMAND)
int_error("expecting dummy variable name", c_token);
else
copy_str(dummy_var,c_token++);
}
else if (almost_equals(c_token,"fo$rmat")) {
BOOLEAN setx, sety;
c_token++;
if (equals(c_token,"x")) {
setx = TRUE; sety = FALSE;
c_token++;
}
else if (equals(c_token,"y")) {
setx = FALSE; sety = TRUE;
c_token++;
}
else if (equals(c_token,"xy") || equals(c_token,"yx")) {
setx = sety = TRUE;
c_token++;
}
else if (isstring(c_token) || END_OF_COMMAND) {
/* Assume he wants both */
setx = sety = TRUE;
}
if (END_OF_COMMAND) {
if (setx)
(void) strcpy(xformat,DEF_FORMAT);
if (sety)
(void) strcpy(yformat,DEF_FORMAT);
}
else {
if (!isstring(c_token))
int_error("expecting format string",c_token);
else {
if (setx)
quote_str(xformat,c_token);
if (sety)
quote_str(yformat,c_token);
c_token++;
}
}
}
else if (almost_equals(c_token,"fu$nction")) {
c_token++;
if (!almost_equals(c_token,"s$tyle"))
int_error("expecting keyword 'style'",c_token);
func_style = get_style();
}
else if (almost_equals(c_token,"la$bel")) {
c_token++;
set_label();
}
else if (almost_equals(c_token,"nola$bel")) {
c_token++;
set_nolabel();
}
else if (almost_equals(c_token,"lo